r=int(input())
if r<=9999 and r>=1000:
    a=r%10
    b=r%100//10
    c=r//100%10
    d=r//1000
    s=[r,a,b,c,d]
    s.append(b*10+a)
    s.append(c*10+b)
    s.append(d*10+c)
    s.append(d*100+c*10+b)
    s.append(c*100+b*10+a)
    maxz=[0]
    for x in s:
        count=0
        for i in range(2,x):
            if x%i==0:
                count+=1
        if count==0:
            maxz.append(x)
    print(max(maxz))
else:
    print(0)
    exit()
        
    
    
